<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:tei="http://www.tei-c.org/ns/1.0"
	exclude-result-prefixes="xs"
	version="2.0">
	<xsl:output method="text" encoding="UTF-8"/>


	<xsl:template match="/">
        <xsl:variable name="allnodes" select="//node()"></xsl:variable>
	    <xsl:for-each select="distinct-values(//element()/local-name())">
	        <xsl:variable name="elementName" select="."/>
	        
	        
	        <xsl:choose>
	            <xsl:when test="every $childElement in $allnodes//element()[local-name() eq $elementName]/child::node() 
	                satisfies ($childElement instance of element()) or ($childElement instance of text() and matches($childElement , '[\W]$'))">
	                <xsl:value-of select="."/> {
	                   display: block;
	                   margin-left: 20px;
	                   border: 1px #787878 solid;
	                   padding: 10px;
	                }
	            </xsl:when>
	            <xsl:otherwise>
	                <xsl:value-of select="."/> {
	                   display: inline;
	                }
	            </xsl:otherwise>
	        </xsl:choose>

		    <xsl:value-of select="."/>
	        <xsl:text>:before {&#x20;</xsl:text>
	        <xsl:text>content: " </xsl:text><xsl:value-of select="."/><xsl:text> "</xsl:text>
	        
	        <xsl:variable name="attributes" select="distinct-values($allnodes//element()[local-name() eq $elementName]/local-name(attribute::node()[1] ) )"></xsl:variable>
	        <xsl:for-each select="$attributes">
	            <xsl:if test=". != ''">
	                <xsl:text>"- </xsl:text><xsl:value-of select="."/>
	                <xsl:text>: " attr(</xsl:text><xsl:value-of select="."/><xsl:text>)</xsl:text>
	            </xsl:if>
	        </xsl:for-each>
	        <xsl:text>;</xsl:text>
		    <xsl:text>}</xsl:text>
   
		</xsl:for-each>
	</xsl:template>
	
</xsl:stylesheet>